//563. 二叉树的坡度

#include <stdio.h>
struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
};
int dfs(struct TreeNode* root){
    if(NULL == root)
        return 0;
    
    return root->val + dfs(root->left) + dfs(root->right);
}
int findTilt(struct TreeNode* root){
    if(NULL == root)
        return 0;
    else
        return abs(dfs(root->left) - dfs(root->right))
            + findTilt(root->left) + findTilt(root->right);
}